package com.zeta.auth.api;

import cn.dev33.satoken.stp.StpInterface;
import com.zeta.api.client.auth.IAuthApi;
import io.swagger.v3.oas.annotations.Hidden;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.zetaframework.controller.SuperBaseController;

import java.util.List;

/**
 * 鉴权服务 Feign接口实现
 *
 * @author gcc
 */
@Hidden // swagger文档忽略
@Slf4j
@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
public class AuthApiImpl implements SuperBaseController, IAuthApi {

    private final StpInterface stpInterface;

    /**
     * 返回指定账号id所拥有的权限码集合
     *
     * @param loginId   账号id
     * @param loginType 账号类型
     * @return 该账号id具有的权限码集合
     */
    @Override
    @GetMapping("/userInfo/permissions")
    public List<String> permissions(@RequestParam Object loginId, @RequestParam(required = false) String loginType) {
        return stpInterface.getPermissionList(loginId, loginType);
    }

    /**
     * 返回指定账号id所拥有的角色标识集合
     *
     * @param loginId   账号id
     * @param loginType 账号类型
     * @return 该账号id具有的角色标识集合
     */
    @Override
    @GetMapping("/userInfo/roles")
    public List<String> roles(@RequestParam Object loginId, @RequestParam(required = false) String loginType) {
        return stpInterface.getRoleList(loginId, loginType);
    }
}
